package com.bluefish.bltuan.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

import com.bluefish.bltuan.module.shop.Order;
import com.bluefish.bltuan.module.shop.Ticket;
import com.bluefish.bltuan.module.user.User;
import com.bluefish.bltuan.service.OrderService;
import com.bluefish.bltuan.service.TicketService;

@Results({
	@Result(name = "index", type = "dispatcher", location = "/page/myTuan.jsp"),
	@Result(name = "tickets", type = "dispatcher", location = "/page/myTickets.jsp"),
	@Result(name = "setting", type = "dispatcher", location = "/page/mySetting.jsp")
})
public class ConsoleAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private OrderService orderService;
	
	private TicketService ticketService;
	
	private List<Order> orders;
	
	private List<Ticket> tickets;
	
	private User user;
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Ticket> getTickets() {
		return tickets;
	}

	public void setTickets(List<Ticket> tickets) {
		this.tickets = tickets;
	}

	public void setTicketService(TicketService ticketService) {
		this.ticketService = ticketService;
	}

	public List<Order> getOrders() {
		return orders;
	}

	public void setOrders(List<Order> orders) {
		this.orders = orders;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	@Override
	public HttpHeaders index() {
		User currentuser = (User) getCurrentUser();
		if(currentuser != null){
			this.orders = this.orderService.getOrdersByUser(currentuser, getPageIndex());
		}
		return new DefaultHttpHeaders(INDEX).disableCaching();
	}

	public String orders(){
		User currentuser = (User) getCurrentUser();
		if(currentuser != null){
			this.orders = this.orderService.getOrdersByUser(currentuser, getPageIndex());
		}
		return INDEX;
	}
	
	public String tickets(){
		User currentuser = (User) getCurrentUser();
		if(currentuser != null){
			this.tickets = this.ticketService.listByUser(currentuser, getPageIndex());
		}
		return "tickets";
	}
	
	public String setting(){
		this.user = (User) getCurrentUser();
		return "setting";
	}
	
	@Override
	public HttpHeaders show() {
		return null;
	}

	@Override
	public HttpHeaders create() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HttpHeaders editNew() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String update() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String edit() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

}
